﻿using System.Collections;
using System.Configuration;
using MPMovieCatalog.Configuration.Sections;

namespace MPMovieCatalog.Configuration
{
    public class ConfigurationWrapper
    {
        private System.Configuration.Configuration m_configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

        public ConnectionSection ConnectionSection
        {
            get
            {
                ConnectionSection section = (ConnectionSection)m_configuration.Sections["connection"];
                if (section == null)
                {
                    section = new ConnectionSection();
                    section.Host = "localhost";
                    section.Port = 8080;
                    m_configuration.Sections.Add("connection", section);
                }
                return section;
            }
        }

        public ScriptSection ScriptSection
        {
            get
            {
                ScriptSection section = (ScriptSection)m_configuration.Sections["scripts"];
                if (section == null)
                {
                    section = new ScriptSection();
                    section.Scripts = new ArrayList();
                    m_configuration.Sections.Add("scripts", section);
                }
                return section;
            }
        }

        public GUISection GUISection
        {
            get
            {
                GUISection section = (GUISection)m_configuration.Sections["interface"];
                if (section == null)
                {
                    section = new GUISection();
                    section.Language = "English";
                    m_configuration.Sections.Add("interface", section);
                }
                return section;
            }
        }

        public void SaveConfiguration()
        {
            m_configuration.Save();
        }
    }
}
